package cn.ekuma.epos.datalogic.define.dao.erp;

import java.util.List;

import com.openbravo.data.loader.query.QBFParameters;
import e.odbo.data.dao.ViewDAO;

import com.openbravo.bean.erp.viewbean.PassengerFlowAnalysisInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;

import com.openbravo.data.loader.sentence.StaticSentence;

public class PassengerFlowAnalysisInfoDAO extends ViewDAO<PassengerFlowAnalysisInfo>{

    public PassengerFlowAnalysisInfoDAO(I_Session s) {
        super(s);
    }

    @Override
    public Class getSuportClass() {
        return PassengerFlowAnalysisInfo.class;
    }

    public PassengerFlowAnalysisInfo readValues(DataRead dr,PassengerFlowAnalysisInfo obj) throws BasicException {
    	if(obj==null)
    		obj=new PassengerFlowAnalysisInfo();
    	obj.setHostName(dr.getString(1));
    	obj.setLocation(dr.getString(2));
    	obj.setType(dr.getInt(3));
    	obj.setUnit(dr.getDouble(4));
    	obj.setTotalPrice(dr.getDouble(5));
    	obj.setConsultCost(dr.getDouble(6));
        return obj;
    }

   public List<PassengerFlowAnalysisInfo> list(Object filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  T.HOSTNAME,S.NAME, T.TICKETTYPE, COUNT(*), SUM(T.TOTALPRICE),SUM(TOTALCONSULTCOST)  "
                + "FROM TICKETS T "
                + "LEFT OUTER JOIN CUSTOMERS C ON  T.CUSTOMER=C.ID "
                + "LEFT OUTER JOIN LOCATIONS S ON T.LOCATIONREF=S.ID "
                + "WHERE ?(QBF_FILTER) "
                + "GROUP BY T.HOSTNAME,S.NAME, T.TICKETTYPE  ORDER BY T.CURDATE DESC ", new String[]{ "T.CURDATE", "T.CURDATE", "T.CUSTOMER"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.STRING}), this).list(filter);
    }

    @Override
    public List<PassengerFlowAnalysisInfo> query(QBFParameters qbfParameters) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  T.HOSTNAME,S.NAME, T.TICKETTYPE, COUNT(*), SUM(T.TOTALPRICE),SUM(TOTALCONSULTCOST)  "
                        + "FROM TICKETS T "
                        + "LEFT OUTER JOIN CUSTOMERS C ON  T.CUSTOMER=C.ID "
                        + "LEFT OUTER JOIN LOCATIONS S ON T.LOCATIONREF=S.ID "
                        + "WHERE ?(QBF_FILTER) "
                        + "GROUP BY T.HOSTNAME,S.NAME, T.TICKETTYPE  ORDER BY T.CURDATE DESC "),null, this).list(qbfParameters);

    }
}
